#include "util.hpp"
#include <string>  
#include "db.hpp"
#define HOST "127.0.0.1"
#define USER "root"
#define PASS "123456"
#define DBNAME "gobang"
#define PORT 3306
void mysql_test(){
// 将字符串常量转换为std::string以匹配参数类型
    std::string host = HOST;
    MYSQL *mysql = mysql_util::mysql_create(host, USER, PASS, DBNAME, PORT);
    
    if (mysql == nullptr) {  
        return ;
    }
    
    // 明确指定表名和字段，避免歧义
    const char *sql = "insert stu values(null,'小黑', 18, 54, 63, 56);";
    bool ret = mysql_util::mysql_exec(mysql, sql);
    
    if (ret == false) {
        mysql_util::mysql_destroy(mysql);  // 出错时也需要释放资源
        return ;
    }
    
    mysql_util::mysql_destroy(mysql);
}
void json_test(){
Json::Value root;
std::string body;
root["姓名"]="小马";
root["年龄"]=14;
root["成绩"].append(98);
root["成绩"].append(28);
root["成绩"].append(38);
json_util::serialize(root ,body);
DLOG("%s",body.c_str());
Json::Value val;
json_util::unserialize(body,val);
std::cout<<"姓名:"<<val["姓名"].asString()<<std::endl;
std::cout<<"年龄:"<<val["年龄"].asInt()<<std::endl;
int sz=val["成绩"].size();
for(int i=0;i<sz;i++){
std::cout<<"成绩:"<<val["成绩"][i].asFloat()<<std::endl;
}
}
void str_test(){
	std::string str="123,123,324,,,121";
	std::vector <std::string> arry;
	string_util::split(str,",",arry);
	for(auto a:arry){
		DLOG("%s",a.c_str());
	}
}
void file_test(){
	std::string filename="./makefile";
	std::string body;
	file_util::read(filename,body);
	std::cout<< body <<std::endl;
}
void db_test(){
	user_table ut(HOST,USER,PASS,DBNAME,PORT);
	Json::Value user;
	//user["username"]="xiaoming";
	//user["password"]="123123";
//ut.insert(user);
	bool ret=ut.win(1);
//std::string body;
//json_util::serialize(user,body);
/*if(ret==false){
DLOG("login failed");
}*/
//std::cout<<body<<std::endl;
}
int main() {
    //json_test();
	//str_test();
	//file_test();
	db_test();
    return 0;
}
